package com.java.basis.stream;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @author wangning
 * @create 2022-01-07 15:04
 */
public class StreamTest01 {
	@Test
	public void test01() {
		List<String> list = new ArrayList<>();
		list.add("aaa");
		list.add("bbb");
		list.add("ccc");
		list.add("abc");
		list.forEach(System.out::println);
		list.forEach((i) ->{
			System.out.println(list.indexOf(i));
		} );
		Stream<String> a = list.stream().filter(name -> name.startsWith("a"));
		System.out.println("-----------------------");
		a.forEach(System.out::println);
		list.forEach(System.out::println);
		list.stream().filter(name -> name.startsWith("a")).forEach(System.out::println);

		list.stream().filter(aa -> {
			return false;//return true;
		}).forEach(System.out::println);

		list.stream().map(ele -> ele + "12").forEach(System.out::println);

	}
	@Test
	public void test02() {
		String reg = "[A-Z][A-Za-z\\d]*Test(s|Case)?|Test[A-Z][A-Za-z\\d]*";
		String s1 = "A01Test";

		System.out.println(s1.matches(reg));

	}


	@Test
	public void test03() {
		Map<String, String> map = new HashMap<>();
		map.put("a", "1");
		map.put("b", "2");
		map.put("c", "3");

		map.entrySet().stream().forEach((entry) -> {
			System.out.println(entry.getKey());
			System.out.println(entry.getValue());
		});
		System.out.println("---------------------------------");
		map.forEach((key, value) -> {
			System.out.println(key);
			System.out.println(value);
		});

	}
}
